package memento.general;

/**
 * @Author：LJ
 * @Description：发起人橘色
 * @Date: 2017/12/1
 * @Modified By:
 */
public class Originator implements Cloneable {

    private String state;

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    //创建一个备忘录
    public Memento createMemento() throws CloneNotSupportedException {
        return new Memento(state);
        //return clone();
    }

    //恢复一个备忘录
    public void restoreMemento(Memento memento) {
        //在恢复之前应该进行断言,防止空指针
        setState(memento.getState());
    }

    @Override
    protected Originator clone() throws CloneNotSupportedException {
        return (Originator) super.clone();
    }
}
